package com.masz.sort;

import org.apache.commons.lang.math.RandomUtils;

public class Util {

    public static void exchange(int[] arr, int i, int j) {

        arr[i] = arr[i] ^ arr[j];
        arr[j] = arr[i] ^ arr[j];
        arr[i] = arr[i] ^ arr[j];

    }

    public static void sout(int[] arr) {
        for (int i : arr) {
            System.out.print(i + ",");
        }
        System.out.println();
    }

    public static boolean equals(int[] arr1, int[] arr2) {
        if (arr1 == null && arr2 == null) {
            return true;
        }
        if (arr1 != null && arr2 == null) {
            return false;
        }

        if (arr1 == null && arr2 != null) {
            return false;
        }
        if (arr1.length != arr2.length) {
            return false;
        }
        for (int i = 0; i < arr1.length; i++) {
            if (arr1[i]!=arr2[i]) {
                return false;
            }
        }
        return true;
    }

    public static int[] generate(int length, int maxValue) {

        if (length<=0 || maxValue<=0) {
            throw new RuntimeException("param err");
        }

        int[] arr = new int[length];

        for (int i = 0; i < length; i++) {
            arr[i] = RandomUtils.nextInt(maxValue);
        }

        return arr;

    }

}
